<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@ include file="/common/common-css.v2.jsp" %>
    <style>
        #jquery-table td {
            cursor: pointer !important;
            word-break: break-all;
            word-wrap: break-word;
        }

        .load_bg {
            background: #000;
            opacity: 0.1;
            left: 0;
            top: 0;
            position: fixed;
            height: 100%;
            width: 100%;
            overflow: hidden;
            z-index: 10000;
        }

        .load_img {
            left: 50%;
            top: 180px;
            position: fixed;
            height: 50px;
            overflow: hidden;
            z-index: 20000;
        }
    </style>
</head>
<body class="no-skin">
<div class="load_bg" style="display:none;"></div>
<img src="http://img.xmiles.cn/commentloading.gif" class="load_img" style="display:none"/>
<div class="page-content">
    <form id="queryForm" method="post">
        <div class="page-content-area">
            <div class="row">
                <div class="col-sm-12">
                    <div class="widget-box" style="border:0 solid #ccc; border-top:none;border-bottom:none;">

                        <div class="widget-header widget-header-blue widget-header-flat">
                            <h4 class="widget-title">选择条件进行查询</h4>
                            <div class="widget-toolbar">
                                <a href="#" data-action="collapse">
                                    <i class="ace-icon fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>

                        <div class="widget-body">
                            <div class="widget-main clearfix">

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" style="text-align:right"
                                           for="startDate">发送开始时间:</label>
                                    <div class="col-sm-8">
                                        <div class="input-daterange input-group">
                                            <input type="text" class="date-picker form-control"
                                                   data-date-format="yyyy-mm-dd" style="padding-left:0"
                                                   name="startDate" id="startDate" placeholder="发送开始时间">
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" style="text-align:right"
                                           for="endDate">发送结束时间:</label>
                                    <div class="col-sm-8">
                                        <div class="input-daterange input-group">
                                            <input type="text" class="date-picker form-control"
                                                   data-date-format="yyyy-mm-dd" style="padding-left:0"
                                                   name="endDate" id="endDate" placeholder="发送结束时间">
                                        </div>
                                    </div>
                                </div>

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="phone"
                                           style="text-align:right;">手机号码:</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="phone" id="phone"
                                               placeholder="查询手机号">
                                    </div>
                                </div>
                                
                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="remark"
                                           style="text-align:right;">备注:</label>
                                    <div class="col-sm-8">
                                        <input type="text" class="form-control" name="remark" id="remark"
                                               placeholder="查询备注">
                                    </div>
                                </div>

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="product"
                                           style="text-align:right;">所属产品:</label>
                                    <div class="col-sm-8">
                                        <select class="form-control" name="product" id="product">
                                            <option value="" selected>全部</option>
                                            <option value="8000">菠萝贷</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="form-group col-xs-12 col-sm-4">
                                    <label class="col-sm-4 control-label" for="product"
                                           style="text-align:right;">上传批量发送短信EXCEL:</label>
                                    <div class="col-sm-8">
                                        <input id="upload" type="file" name="upload">
                                    </div>
                                </div>

                                <%--<div class="form-group col-xs-12 col-sm-4 col-md-3 col-lg-3" style="text-align:left">
										<span id="upload">
											<input id="uploadfile_wx" name="upload" type="file" size="1"
                                                   style="position:absolute; z-index:100; margin-left:-130px; font-size:60px;opacity:0;filter:alpha(opacity=0); margin-top:-5px;"/>
											<input id="uploadbtn_wx" type='button' class='btn' value='导入批量短信...'/>
										</span>
                                </div>--%>

                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-md-12 center">
                    <div class="clearfix form-actions">
                        <button class="btn btn-purple no-border" type="button" name="btn-query" onclick="query()"
                                id="btn-query">
                            <i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
                            查询
                        </button>
                        &nbsp;&nbsp;&nbsp;
                        <button class="btn btn-purple no-border" type="button" name="btn-query" id="exportSms">
                            <i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
                            导出
                        </button>
                        &nbsp;&nbsp;&nbsp;
                        <button class="btn btn-grey no-border" type="reset">
                            <i class="ace-icon fa fa-undo icon-on-right bigger-110"></i>
                            重置
                        </button>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-12">
                    <table id="jquery-table" class="table table-striped table-bordered table-hover">
                    </table>
                </div>
            </div>

        </div>
    </form>
</div>


<%@ include file="/common/common-js.jsp" %>
<script type="text/javascript">
    var loadDom = $('.load_bg,.load_img');
    var jqTable = null;
    var startDateDom = $('#startDate');
    var endDateDom = $('#endDate');

    $('#exportSms').click(function () {
        var st = startDateDom.val(),
                et = endDateDom.val();
        if (!st || !et) {
            alert('请输入开始时间和结束时间');
            return;
        }

        var form = document.forms["queryForm"];
        var url = ctx + "/message/short_message_export.action";
        form.action = encodeURI(url);
        form.submit();
    });

    function query() {
        loadDom.show();
        if (jqTable != null) {
            jqTable.fnDraw();
        }
        else {
            loadData();
        }
    }

    var loadData = function () {
        jqTable = $('#jquery-table').dataTable({
            "columnDefs": [
                {
                    "title": '发送时间',
                    "targets": [0],
                    "data": "ctime",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '手机号',
                    "targets": [1],
                    "data": "phoneNum",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '发送内容',
                    "targets": [2],
                    "data": "content",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '备注',
                    "targets": [3],
                    "data": "memo",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px"
                },
                {
                    "title": '发送状态',
                    "targets": [4],
                    "data": "status",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px",
                    "render": function (d) {
                        switch (d) {
                            case 1:
                                return '成功';
                            case 0:
                                return '失败';
                            default:
                                return d;
                        }
                    }
                },
                {
                    "title": '短信商',
                    "targets": [5],
                    "data": "channel",
                    "class": "center",
                    "bSortable": false,
                    "width": "50px",
                    "render": function (d) {
                        switch (d) {
                            case 3:
                                return '昊博';
                            case 6:
                                return '梦网科技';
                            case 8:
                            	return "创蓝";
                            default:
                                return d;
                        }
                    }
                }
            ],
            "sAjaxSource": ctx + "/message/short_message_list.action",
            "fnServerData": function (url, aoData, fnCallback) {
                var data = $('#queryForm').serializeObject();
                data.aoData = JSON.stringify(aoData);
                $.ajax({
                    "type": "POST",
                    "dataType": 'json',
                    "url": url,
                    "data": data,
                    "success": function (resp) {
                        try {
                            fnCallback(resp);
                        } catch (e) {
                            alert(e.name + ' :' + e.message)
                        }
                        //initListPage();
                    },
                    "error": function (XMLHttpRequest, textStatus) {
                        alert(textStatus);
                        loadDom.hide();
                    },
                    "complete": function () {
                        loadDom.hide();
                    }
                });
            },
            "sScrollXInner": "100%",
            "sScrollY": "100%",
            "aaSorting": [[0, "desc"]]
        });
    };

    jQuery(function ($) {
        $(".date-picker").datepicker({autoclose: true}).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });

        $('#upload').change(function () {
            var $form = document.forms["queryForm"];
            $($form).attr('enctype', 'multipart/form-data');
            $form.action = ctx + "/message/uploadSmsBatch.action";
            $form.submit();
        });
    });
</script>
</body>
</html>